#读取视频参数信息
import cv2
import numpy as np


video_path = "./input_video.mp4"
cap = cv2.VideoCapture(video_path)

if not cap.isOpened():
    print(f"无法打开视频文件: {video_path}")
    exit()

fps = cap.get(cv2.CAP_PROP_FPS)
frame_count = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
duration = frame_count / fps if fps > 0 else 0

print(f"视频信息:")
print(f"  帧率: {fps:.2f} FPS")
print(f"  总帧数: {frame_count}")
print(f"  时长: {duration:.2f} 秒")

frame = cv2.imread("./test.jpg")
frame1 = frame[930:1090,650:790]
print("类型：",type(frame[0][0][0]))
cv2.imwrite("test1.jpg",frame1)

frame4 = frame[720:850,1880:2240]
print("类型：",type(frame[0][0][0]))
cv2.imwrite("test2.jpg",frame4)

"""
#默认uint8，需转成int16，否则会溢出。
frame2 = cv2.imread("./frame_810.jpg")
frame2 = frame2[210:720,1880:2240]
frame = frame.astype(np.int16)
frame2 = frame2.astype(np.int16)
print("1:",frame[0][0][0].dtype)
print("2:",frame2[0][0][0].dtype)
frame = frame[210:720,1880:2240]
frame3 = frame2 - frame
print("3:",frame3[0][0][0].dtype)
frame3 = abs(frame3)
cv2.imwrite("test3.jpg",frame3)
print("1",frame)
print("2",frame2)
print("3",frame3)"""
